﻿@page "/auth/logout"
@using Gardener.Client.Base;
@using Microsoft.AspNetCore.Authorization;
@using Microsoft.Extensions.Options;
@using System.Diagnostics.CodeAnalysis;
@layout Gardener.Client.BootstrapUi.Base.Shared.LoginLayout
@attribute [AllowAnonymous]

@code {

    [Inject]
    public IAuthenticationStateManager authenticationStateManager { get; set; } = null!;

    [Inject]
    private IOptions<AuthSettings> authSettingsOpt { get; set; } = null!;

    [Inject]
    private NavigationManager NavigationManager { get; set; } = null!;
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    protected override async Task OnInitializedAsync()
    {
        //已登录
        var user = await authenticationStateManager.GetCurrentUser();
        if (user != null)
        {
            await authenticationStateManager.Logout();
            NavigationManager.NavigateTo(authSettingsOpt.Value.LoginPagePath);
        }
        await base.OnInitializedAsync();
    }
}
